/*********************************
* John Clayton
* Assignment 4
* CS362
* Random Test salvager
*********************************/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>

#define NUM_TESTS 10000 //Number of times to run the test

int main(){
   int i,
       j,
       k,
       player,
       numPlayers,
       handPos,
       bonus = 0,
       newSize,
       preCoins,
       postCoins,
       preHandCount,
       choice1,
       cardValue,
       preBuys;
   int kCards[10] = {salvager, ambassador, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
   struct gameState *state;
   enum CARD card = salvager;
   enum CARD firstCard = adventurer;
   enum CARD lastCard = treasure_map;
   PlantSeeds(3);
   SelectStream(0);
   assert(state != 0);

   printf("Beginning testing card: Salvager\n**************************************\n");
   for(i = 0; i <= NUM_TESTS; i++){
      state = newGame();
      numPlayers = (((int) (Random() * 1000))%4) + 1;
      initializeGame(numPlayers, kCards,(int) (Random()*256), state);
      player = state->whoseTurn;

      //New deck size for player between 5-60.
      newSize = (((int) (Random() * 1000))%56)+5;
      state->handCount[player] = newSize;

      //fills a giant hand
      for(j = 0; j < newSize; j++)
	 state->hand[player][j] = (int) (Random() * 256) % (treasure_map - curse);

      //Gets a card to discard and its value
      choice1 = (((int) (Random() * 1000))%newSize-1) + 1;
      cardValue = getCost(state->hand[player][choice1]);

      //Adds a bunch of buys
      preBuys = state->numBuys = (((int) (Random() * 1000))%newSize-1) + 1;

      //Put a salvager at the beginning of the hand
      handPos = 0;
      state->hand[player][handPos] = salvager;

      //Find the starting number of coins in hand, size of hand
      updateCoins(player, state, bonus);
      preCoins = state->coins;
      preHandCount = state->handCount[player];

      //Play card
      cardEffect(card, choice1, 0, 0, state, handPos, &bonus);

      //Find final number of coins in hand
      updateCoins(player, state, bonus);
      postCoins = state->coins;

      printf("[Test %d]:\n", i);
      if(preCoins + cardValue == postCoins)
	 printf("\tPASS on getting coins. (should have: %d, has: %d)\n", preCoins + cardValue, postCoins);
      else
	 printf("\tFAIL on getting coins. (should have: %d, has: %d)\n", preCoins + cardValue, postCoins);
      if(preBuys + 1 == state->numBuys)
	 printf("\tPASS on number of buys. (should have: %d, has: %d)\n", preBuys + 1, state->numBuys);
      else
	 printf("\tFAIL on number of buys. (should have: %d, has: %d)\n", preBuys + 1, state->numBuys);
      if(preHandCount - 2 == state->handCount[player])
	 printf("\tPASS on hand size. (should have: %d, has: %d)\n", preHandCount - 2, state->handCount[player]);
      else
	 printf("\tFAIL on hand size. (should have: %d, has: %d)\n", preHandCount - 2, state->handCount[player]);
   }
   printf("Ending testing card: Salvager\n***********************************\n");
   return 0;
}
